package lueerror

import (
	"errors"
	"net/http"
)

// UnhandledErr 未捕捉错误
func UnhandledErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50000",
		error:      err,
		msg:        "服务器开小差了~",
		sendMail:   true,
	}
}

// InvalidRequest 请求参数错误
func InvalidRequest(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40001",
		error:      err,
		msg:        "参数错误",
		sendMail:   false,
	}
}

// DbErr postgresql 异常
func DbErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50001",
		error:      err,
		msg:        "服务器开小差了~",
		sendMail:   true,
	}
}

// RedisErr redis 异常
func RedisErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50002",
		error:      err,
		msg:        "服务器开小差了~",
		sendMail:   true,
	}
}

// MqErr 消息中间件异常
func MqErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50003",
		error:      err,
		msg:        "服务器开小差了~",
		sendMail:   true,
	}
}

// GrpcErr grpc 异常
func GrpcErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50004",
		error:      err,
		msg:        "服务器开小差了~",
		sendMail:   true,
	}
}

// OpenErr 第三方授权平台调用
func OpenErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50005",
		error:      err,
		msg:        "第三方授权平台调用失败",
		sendMail:   true,
	}
}

// BilinAdminErr 授权平台调用
func BilinAdminErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50006",
		error:      err,
		msg:        "比邻Admin服务调用失败",
		sendMail:   true,
	}
}

// BilinSmsErr 授权平台调用
func BilinSmsErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50006",
		error:      err,
		msg:        "短信服务调用失败",
		sendMail:   true,
	}
}

// BilinPayErr 比邻支付调用失败
func BilinPayErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusInternalServerError,
		code:       "50005",
		error:      err,
		msg:        "比邻支付服务调用失败",
		sendMail:   true,
	}
}

// MobileHasUsed 手机号已经使用
func MobileHasUsed(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusNotAcceptable,
		code:       "40002",
		error:      err,
		msg:        "手机号已经被使用",
		sendMail:   false,
	}
}

// HasNoPermission 无权限操作
func HasNoPermission() LueError {
	return &errInfo{
		httpStatus: http.StatusForbidden,
		code:       "40003",
		error:      errors.New("无权限操作"),
		msg:        "无权限操作",
		sendMail:   false,
	}
}

// AccNotExit 账号不存在
func AccNotExit(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusNotFound,
		code:       "40004",
		error:      err,
		msg:        "用户账号不存在",
		sendMail:   false,
	}
}

// InvalidPassword 登陆认证失败
func InvalidPassword(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnauthorized,
		code:       "40005",
		error:      err,
		msg:        "请出入正确的密码",
		sendMail:   false,
	}
}

// EmailHasUsed 邮箱已经使用
func EmailHasUsed(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusNotAcceptable,
		code:       "40006",
		error:      err,
		msg:        "邮件已经被使用",
		sendMail:   false,
	}
}

// CodeVerifyFailed 验证码验证失败
func CodeVerifyFailed(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnauthorized,
		code:       "40007",
		error:      err,
		msg:        "验证失败",
		sendMail:   false,
	}
}

// AuthGrantErr 授权失败
func AuthGrantErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnauthorized,
		code:       "40008",
		error:      err,
		msg:        "授权失败",
		sendMail:   false,
	}
}

// PreventLogin 登陆错误
func PreventLogin(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnauthorized,
		code:       "40009",
		error:      err,
		msg:        "登陆失败",
		sendMail:   false,
	}
}

// InvalidMobile 手机号错误
func InvalidMobile(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40010",
		error:      err,
		msg:        "手机号格式错误",
		sendMail:   false,
	}
}

// InvalidEmail 邮箱格式错误
func InvalidEmail(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40011",
		error:      err,
		msg:        "邮箱格式错误",
		sendMail:   false,
	}
}

// GroupExist 体系已经存在
func GroupExist(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40012",
		error:      err,
		msg:        "体系已经存在",
		sendMail:   false,
	}
}

// GroupNotExist 体系不存在
func GroupNotExist(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40013",
		error:      nil,
		msg:        "会员卡不存在",
		sendMail:   false,
	}
}

// CardNotExist 等级不存在
func CardNotExist(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40014",
		error:      err,
		msg:        "会员卡不存在",
		sendMail:   false,
	}
}

// InvalidCardConfig 卡配置参数错误
func InvalidCardConfig(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40015",
		error:      err,
		msg:        "等级配置错误",
		sendMail:   false,
	}
}

// MemberNotExist 用户不存在
func MemberNotExist(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusNotFound,
		code:       "40016",
		error:      err,
		msg:        "用户不存在",
		sendMail:   false,
	}
}

// InvalidStatus 状态类型错误
func InvalidStatus(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnprocessableEntity,
		code:       "40017",
		error:      err,
		msg:        "状态类型错误",
		sendMail:   false,
	}
}

// DirtyData 脏数据
func DirtyData(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnprocessableEntity,
		code:       "40018",
		error:      err,
		msg:        "数据有误，请联系后台排查",
		sendMail:   false,
	}
}

// InvalidMember 不可用用户
func InvalidMember(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnprocessableEntity,
		code:       "40019",
		error:      err,
		msg:        "当前用户不可用",
		sendMail:   false,
	}
}

// TopupLimit 充值金额不符
func TopupLimit(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40020",
		error:      err,
		msg:        "充值金额不符",
		sendMail:   false,
	}
}

// StoreNotAllowed 门店不适用
func StoreNotAllowed(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40021",
		error:      err,
		msg:        "该门店不适用",
		sendMail:   false,
	}
}

// InvalidAccount 账号不可用
func InvalidAccount(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnprocessableEntity,
		code:       "40022",
		error:      err,
		msg:        "账号不可用",
		sendMail:   false,
	}
}

// RechargeForbidden 不允许充值
func RechargeForbidden(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnprocessableEntity,
		code:       "40023",
		error:      err,
		msg:        "当前账号不可充值",
		sendMail:   false,
	}
}

// OrderCantBePayed 订单无法支付
func OrderCantBePayed(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40024",
		error:      err,
		msg:        "订单无法支付",
		sendMail:   false,
	}
}

// OrderNotExist 订单不存在
func OrderNotExist(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusNotFound,
		code:       "40025",
		error:      err,
		msg:        "订单不存在",
		sendMail:   false,
	}
}

// OrderIsFinished 订单已经完结
func OrderIsFinished(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnprocessableEntity,
		code:       "40025",
		error:      err,
		msg:        "订单已经完结",
		sendMail:   false,
	}
}

// MemberMissMatch 账号不匹配
func MemberMissMatch(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40026",
		error:      err,
		msg:        "账号不匹配",
		sendMail:   false,
	}
}

// BalanceInsufficient 余额不足
func BalanceInsufficient(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40027",
		error:      err,
		msg:        "余额不足",
		sendMail:   false,
	}
}

// RefundBeyond 退款金额溢出
func RefundBeyond(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40028",
		error:      err,
		msg:        "退款金额溢出",
		sendMail:   false,
	}
}

// PayRepeat 重复支付
func PayRepeat(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40029",
		error:      err,
		msg:        "订单已经支付",
		sendMail:   false,
	}
}

// RefundRepeat 重复退款
func RefundRepeat(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40029",
		error:      err,
		msg:        "订单已经退款",
		sendMail:   false,
	}
}

// IntegralCntErr 积分异常
func IntegralCntErr(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusUnprocessableEntity,
		code:       "40030",
		error:      err,
		msg:        "积分数异常",
		sendMail:   true,
	}
}

// IntegralRepeat 重复积分
func IntegralRepeat(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40031",
		error:      err,
		msg:        "已积分",
		sendMail:   false,
	}
}

// IntegralRefundRepeat 重复退积分
func IntegralRefundRepeat(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40032",
		error:      err,
		msg:        "已退积分",
		sendMail:   false,
	}
}

// IntegralInsufficient 积分不足
func IntegralInsufficient(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40033",
		error:      err,
		msg:        "积分不足",
		sendMail:   false,
	}
}

// InvalidLoginChannel 无效的登陆渠道
func InvalidLoginChannel(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40034",
		error:      err,
		msg:        "无效的渠道",
		sendMail:   false,
	}
}

// MobileRequired 未绑定手机号
func MobileRequired(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40035",
		error:      err,
		msg:        "请绑定手机号",
		sendMail:   false,
	}
}

// InvalidAddress 无效的地址
func InvalidAddress(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40036",
		error:      err,
		msg:        "无效的地址",
		sendMail:   false,
	}
}

// LoginChannelNotExist 登陆渠道不存在
func LoginChannelNotExist(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40037",
		error:      err,
		msg:        "登陆渠道不存在",
		sendMail:   false,
	}
}

// AddressNotExist 未找到有效地址
func AddressNotExist(err error) LueError {
	return &errInfo{
		httpStatus: http.StatusBadRequest,
		code:       "40036",
		error:      err,
		msg:        "未找到有效地址",
		sendMail:   false,
	}
}
